package test;

import dq.node.ListNode;
import written.test.Wangyi;

import java.util.Scanner;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/18  20:10
 * @Description:
 */
public class Tencent1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        t = sc.nextInt();
        grid = new int[n][m];
        for(int i=0; i < n; i++){
            for(int j = 0; j < m; j++){
                grid[i][j] = sc.nextInt();
            }
        }
        dfs(0,0,-1,-1,-1,-1,0,0);
        System.out.println(ans);
    }
    static int t ;
    static int[][] grid;
    static int ans = 0;
    public static void dfs(int i, int j, int lastI, int lastJ, int lastLastI, int lastLastJ, int time, int curValue){
        if(i==lastLastI&&j==lastLastJ) return;
        if(i<0||j<0||i>=grid.length||j>=grid[0].length) return;
        curValue += grid[i][j] <= time ? 1 : 0;
        //如果最后一秒到达随后，记录一个值，否则直接return
        if(time==t){
            if(i==grid.length-1 && j==grid.length-1){
                ans = Math.max(ans, curValue);
            }else return;
        }else{
            //没到最后一秒
            dfs(i+1, j, i, j, lastI, lastJ, time+1, curValue);
            dfs(i-1, j, i, j, lastI, lastJ, time+1, curValue);
            dfs(i, j+1, i, j, lastI, lastJ, time+1, curValue);
            dfs(i, j-1, i, j, lastI, lastJ, time+1, curValue);
        }
    }

}
